﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Micronet.OpenWeb.Com.BLL;
using Micronet.OpenWeb.Com.Controls;
using Micronet.OpenWeb.Utils;

namespace Micronet.OpenWeb.OpenWeb.Admin.Views.Shared.OpenPersonality
{
    public partial class HomeProfileContactInfos : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void IsDefaultCb_CheckedChanged(object sender, EventArgs e)
        {
            var IsDefaultCb = (OwCheckBox)sender;
            if (IsDefaultCb.Checked.ToString().OwToBoolean() == true)
            {
                var ods = OwOpenHomeProfileContactInfosBLL.OwGetByDynamic(null, null, null, null);
                var en = OwOpenHomeProfileContactInfosBLL.OwGetEntity(IsDefaultCb.Text.Trim().OwToInt64TryParse());
                //Response.Write(en.OpenHomeProfileLivingProcessID.ToString());
                foreach (var entity in ods)
                {

                    if (entity.OpenHomeProfileContactInfoID != en.OpenHomeProfileContactInfoID)
                    {
                        entity.IsDefault = false;
                        OwOpenHomeProfileContactInfosBLL.OwSave(entity);
                        
                    }
                    else
                    {
                        entity.IsDefault = true;
                        OwOpenHomeProfileContactInfosBLL.OwSave(entity);
                    }
                }
            }
            else
            {
                var en = OwOpenHomeProfileContactInfosBLL.OwGetEntity(IsDefaultCb.Text.Trim().OwToInt64TryParse());
                en.IsDefault = false;
                OwOpenHomeProfileContactInfosBLL.OwSave(en);
            }
            OpenHomeProfileContactInfoGrid.Rebind();


        }

        protected void IsDeletedCb_CheckedChanged(object sender, EventArgs e)
        {

            var isDeletedCheckBox = (OwCheckBox)sender;
            var obj = OwOpenHomeProfileContactInfosBLL.OwGetEntity(isDeletedCheckBox.Text.Trim().OwToInt64TryParse());
           
            obj.IsDeleted = isDeletedCheckBox.Checked.ToString().OwToBoolean();
            if (OwOpenHomeProfileContactInfosBLL.OwSave(obj) > 0)
            {
              OpenHomeProfileContactInfoGrid.Rebind();
               
            }

        }
    }
}